package com.fivefu.core.hik.controller;

import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hik.constant.HikRequestTypeEnum;
import com.fivefu.core.hik.dto.response.ResponseResult;
import com.fivefu.core.hik.services.HikvisionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "公用接口")
@RestController
@RequestMapping("/common")
public class CommonController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(CommonController.class);

    @Autowired
    private HikvisionService hikvisionService;

    @ApiOperation(value = "获取 access_token ",httpMethod = "GET",response = ResultInfo.class,notes = "获取 access_token ")
    @RequestMapping(path = "queryAccessToken",method = RequestMethod.GET)
    public ResultInfo queryAccessToken(){
        try {
            HikRequestTypeEnum typeEnum = HikRequestTypeEnum.ACCESSTOKEN;
            ResponseResult info = hikvisionService.doPostString(typeEnum.getUrl(), null, null, null, typeEnum.getType());
            return ResultInfo.renderSuccess(info);
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
        return ResultInfo.renderError("获取 access_token 失败");
    }

}
